<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 16/3/21
 * Time: 下午2:47
 */
class ModGameGold
{

    public function indexData($params){
        $where  = ' WHERE RecDate = :date
                        AND Platform=:platform
                        AND Period = :period
                        AND GameSrc=:game
                        AND CoinType = :coinType
                        AND FlowType = :flowType
                        AND Action != "ALL"';

        $args   = array(
            ':date'     => $params['date'],
            ':period'   => "Daily",
            ':game'     => $params['g'],
            ':platform' => $params['p'],
            ':coinType' => $params['coinType'],
            ':flowType' => $params['flowType'],
        );

        if(!empty($params['server']) && $params['server'] !== 'ALL'){
            $where .= 'AND SID=:server';
            $args[':server'] = $params['server'];
        }else{
            $where .= 'AND SID = "ALL"';
        }

        $sql = "SELECT * FROM tblGameGoldAction {$where} order by RecDate desc, SID asc";

        $dbLink = new PubDbLink('dbSelf', PubDatabase::getMgmtDbName($params['p'], $params['g']));
        return $dbLink->query($sql, $args);
    }

    public static function analysisData($params){
        $where = ' WHERE RecDate BETWEEN :t_s AND :t_e
                        AND Period=:period
                        AND Platform=:p
                        AND GameSrc=:g
                        AND SID=:ser
                        AND CoinType=:coinType';

        $args = array(
            ':t_s'      => $params['time_start'],
            ':t_e'      => $params['time_end'],
            ':g'        => empty($params['g']) ? 'ALL' : $params['g'],
            ':p'        => $params['os'],
            ':ser'      => empty($params['server']) ? 'ALL' : $params['server'],
            ':period'   => 'Daily',
            ':coinType' => $params['coinType']
        );

        $table = 'tblGameCoinAction';

        $sql = "SELECT * FROM {$table} {$where}";

        $dbLink = new PubDbLink('dbSelf', PubDatabase::getMgmtDbName($params['p'], $params['g']));
        $res = $dbLink->query($sql, $args);
        return $res;
    }

}